#!/usr/bin/env bash

# ----------------------------------------------------------------------
# Filename	:  chrt_test
# Version	:  1.0
# Date		:  2023/12/05
# Author	:  yaoxiyao
# Email		:  yaoxiyao@kylinos.com.cn 
# History	:     
#              Version 1.0, 2023/12/05
# Function	:  区分实时进程与非实时进程，分别进行调度
# Out		:        
#              0 => TPASS
#              1 => TFAIL
#              other=> TCONF
# ----------------------------------------------------------------------

# 测试主题
Title_Env_LTFLIB="区分实时进程与非实时进程，分别进行调度"



## TODO : 个性化,初始化
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
TestInit_LTFLIB(){
    # 创建临时文件
    testfile_chrt="${TmpTestDir_LTFLIB}/filechrt"
    touch ${testfile_chrt}
    CommRetParse_FailDiy_LTFLIB ${ERROR} "创建文件失败${testfile_chrt}"
    return $TPASS
}


## TODO : 清理函数
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
TestClean_LTFLIB(){
    Debug_LLE "rm -rf ${testfile_chrt}"
    rm -rf ${testfile_chrt}
    return $TPASS
}


## TODO : 测试用例集
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
Testsuite_LTFLIB(){
    testcase_1
    return $TPASS
}


## TODO ： 区分实时进程与非实时进程，分别进行调度
#
testcase_1(){
    export TERM=xterm
    top -b|head -n 50 >> "${testfile_chrt}"
    cat "${testfile_chrt}"|grep "rt"
    CommRetParse_LTFLIB "PR列带有rt字段的为实时进程，否则不是"

    # 实时进程
    local rtid=`cat "${testfile_chrt}" |grep "rt"|awk -F ' ' '{print $1}'|sort -u|sed -n 1p`
    chrt -p "${rtid}"
    CommRetParse_LTFLIB "查看实时进程对应的调度策略和优先级"
    # 非实时进程
    local nort=`cat "${testfile_chrt}" |grep -v "rt"|awk -F ' ' '{print $1}'|sort -n -r|sed -n 2p`
    chrt -p "${nort}"
    CommRetParse_LTFLIB "查看非实时进程对应的调度策略和优先级"
}


#----------------------------------------------#

source "${LIB_LTFLIB}"
Main_LTFLIB $@
